<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.studentmanagement.model.User" %>
<%
    // 检查用户是否已登录
    User user = (User) session.getAttribute("user");
    if (user == null) {
        response.sendRedirect(request.getContextPath() + "/login");
        return;
    }
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加课程 - 学生管理系统</title>
    <link rel="stylesheet" href="<%= request.getContextPath() %>/css/style.css">
</head>
<body>
    <div class="dashboard">
        <header class="header">
            <h1>学生管理系统</h1>
            <div class="user-info">
                欢迎, <%= user.getUsername() %> | <a href="<%= request.getContextPath() %>/logout">退出</a>
            </div>
        </header>
        
        <nav class="sidebar">
            <ul>
                <li><a href="<%= request.getContextPath() %>/student">学生管理</a></li>
                <li><a href="<%= request.getContextPath() %>/course" class="active">课程管理</a></li>
                <li><a href="<%= request.getContextPath() %>/enrollment">选课管理</a></li>
                <li><a href="<%= request.getContextPath() %>/dashboard.jsp">返回控制面板</a></li>
            </ul>
        </nav>
        
        <main class="content">
            <h2>添加课程</h2>
            
            <% if (request.getAttribute("error") != null) { %>
                <div class="error-message">
                    <%= request.getAttribute("error") %>
                </div>
            <% } %>
            
            <form action="<%= request.getContextPath() %>/course/add" method="post" class="form">
                <div class="form-group">
                    <label for="courseName">课程名称:</label>
                    <input type="text" id="courseName" name="courseName" required>
                </div>
                
                <div class="form-group">
                    <label for="creditHours">学分:</label>
                    <input type="number" id="creditHours" name="creditHours" min="1" max="10" required>
                </div>
                
                <div class="form-group">
                    <label for="description">描述:</label>
                    <textarea id="description" name="description" rows="4"></textarea>
                </div>
                
                <div class="form-group">
                    <label for="teacher">教师:</label>
                    <input type="text" id="teacher" name="teacher" required>
                </div>
                
                <div class="form-group">
                    <button type="submit" class="btn">保存</button>
                    <a href="<%= request.getContextPath() %>/course" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </main>
        
        <footer class="footer">
            <p>&copy; 2023 学生管理系统. All rights reserved.</p>
        </footer>
    </div>
</body>
</html>

